package cn.com.validate;

public class RegCommon {

    /**
     * 私有方法，被本类中其他方法调用
     */
    private static boolean isChinese(char c) {
        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
        if(ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
                || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
                || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
                || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION) {
            return true;
        }
        return false;
    }
 
    /**
     *  完整的判断中文汉字和符号
     *  只要是中文输入法输入的字符都返回true
     *  有一个字符不是中文输入就返回false
     * @param strName
     * @return
     */
    public static boolean checkChinese(String strName) {
        char[] ch = strName.toCharArray();
        for(int i = 0; i < ch.length; i++) {
            char c = ch[i];
            if(!isChinese(c)) {
                return false;
            }
        }
        return true;
    }
}
